package com.example.mybatisplusdemo.web.controller;

import com.example.mybatisplusdemo.model.dto.StarCountDTO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.mybatisplusdemo.common.JsonResponse;
import com.example.mybatisplusdemo.service.IRatingService;
import com.example.mybatisplusdemo.model.domain.Rating;

import java.util.List;


/**
 *
 *  前端控制器
 *
 *
 * @author lxp
 * @since 2025-07-04
 * @version v1.0
 */
@RestController
@RequestMapping("/api/rating")
public class RatingController {

    private final Logger logger = LoggerFactory.getLogger( RatingController.class );

    @Autowired
    private IRatingService ratingService;

    @GetMapping("getById")
    public JsonResponse getById(Long id) {
        Rating rating = ratingService.getById(id);
        return JsonResponse.success(rating);
    }

    // 统计评分分布
    @GetMapping("ratingDistribution")
    public JsonResponse ratingDistribution() {
        List<StarCountDTO> dist = ratingService.getRatingDistribution();
        return JsonResponse.success(dist);
    }
}

